var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userVo: {},
    authenticationStatus: false, //认证状态 false 未认证  true 已认证
    authenticationText: '', //认证文本
    passwordText: '',
    address: '', //区地址
    siteName: '',
    contacts: '',
    telephone: '',
    auditStatusText: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
  },

  onMineInfo: function() {
    var that = this
    wx.showLoading({ title: '加载中' })
    wx.request({
      method: 'POST',
      url: app.preUrl + 'findByUserId',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        userId: app.globalData.userId
      },
      success: function(res) {
        console.log(res)
        wx.hideLoading()
        var userVo = res.data.result
        console.log(userVo)
        that.setData({ userVo: userVo })
        if (res.data.result.auditStatus == 1) {
          that.setData({ auditStatusText: '未认证' })
        } else if (res.data.result.auditStatus == 2) {
          that.setData({ auditStatusText: '认证失败' })
        } else if (res.data.result.auditStatus == 3) {
          // ===3 已经认证
          that.setData({ auditStatusText: '认证成功' })
        }
        if (userVo.province) {
          var address =
            userVo.province +
            '' +
            userVo.city +
            '' +
            userVo.area +
            '' +
            userVo.address
          if (address.length > 18) {
            address = address.substring(0, 18) + '...'
          }
          that.setData({
            address: address
          })
        }
        that.setData({
          userVo: userVo,
          address: address,
          siteName: userVo.siteName,
          contacts: userVo.contacts,
          telephone: userVo.telephone
        })
      },
      fail: function(error) {
        console.log(error)
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this
    that.onMineInfo()
  },

  //去认证
  goAuthentication: function() {
    var that = this
    wx.navigateTo({
      url: 'authentication'
    })
  },

  // 选择省市区
  chooseAddress: function(e) {
    var that = this
    wx.navigateTo({
      url: 'modifyAddress?data=' + JSON.stringify(this.data.userVo)
    })
  },
  //更换手机号事件
  modifyPhone: function() {
    wx.navigateTo({ url: 'modifyPhone?telephone=' + this.data.telephone })
  },
  //修改站点名称
  modifySiteName() {
    wx.navigateTo({ url: 'modifySiteName?siteName=' + this.data.siteName })
  },
  //修改联系人
  modifyContacts: function() {
    var that = this
    wx.navigateTo({
      url: 'modifyContacts?contacts=' + that.data.contacts
    })
  },
  goCipher: function() {
    var that = this
    var phone = that.data.userVo.telephone
    if (that.data.userVo.auditStatus != 3) {
      wx.showModal({
        title: '提示',
        content: '身份认证成功才能设置支付密码',
        confirmText: '去认证',
        confirmColor: '#56BDE0',
        success(res) {
          if (res.confirm) {
            // console.log('用户点击确定');
            wx.navigateTo({
              url: 'authentication'
            })
          } else if (res.cancel) {
            //console.log('用户点击取消')
          }
        }
      })
    } else {
      if (that.data.userVo.payStatus == 1) {
        wx.navigateTo({
          url: 'modifyPaymentPassword?phone=' + phone
        })
      } else if (that.data.userVo.payStatus == 2) {
        wx.navigateTo({
          url:
            'checkSetPaymentPassword?phone=' +
            phone +
            '&type=1&name=' +
            that.data.userVo.cardName +
            '&idCard=' +
            that.data.userVo.cardNum //1 新增密码
        })
      }
    }
  }

  //提现密码
  // goCipher:function(){
  //   var that = this;
  //   if (that.data.userVo.auditStatus == 3) {
  //     wx.navigateTo({
  //       url: 'cipher',
  //     })
  //   }

  // },
})
